//
//  Person.m
//  05-CollectionTraversalHomeWork
//
//  Created by 曹曹 on 16/7/8.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "Person.h"

@implementation Person
- (instancetype)initWithName:(NSString *)name age:(NSUInteger)age gender:(NSString *)gender {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _gender = gender;
    }
    return self;
}
- (NSComparisonResult)compareByName:(Person *)anotherPerson {
    return [self.name compare:anotherPerson.name];
}
- (NSComparisonResult)compareByAge:(Person *)anotherPerson {
    if (self.age > anotherPerson.age) {
        return NSOrderedDescending;
    } else if (self.age < anotherPerson.age) {
        return NSOrderedAscending;
    } else {
        return NSOrderedSame;
    }
}
- (NSComparisonResult)compareByGender:(Person *)anotherPerson {
    return [self.gender compare:anotherPerson.gender];
}
- (NSString *)description {
    return [NSString stringWithFormat:@"%@-%ld-%@", _name, _age, _gender];
}
@end
